from collections import OrderedDict
from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response


class PageNum(PageNumberPagination):
    page_size = 5
    page_size_query_param = 'pagesize'
    max_page_size = 10

    def get_paginated_response(self, data):
        return Response(OrderedDict([
            ('count', self.page.paginator.count),     #总共多少条记录
            ('lists', data),                          #结果列表
            ('page', self.page.number),               #第几页
            ('pages', self.page.paginator.num_pages), #总页数
            ('pagesize', self.page_size)              #一页多少条记录
        ]))